Skip to content

Add unit tests for utils/process_result.py with consolidated pytest CI#197

Closed
Copilot wants to merge 5 commits into
mainfrom
copilot/write-unit-test-for-utils
Closed

Add unit tests for utils/process_result.py with consolidated pytest CI#197
Copilot wants to merge 5 commits into
mainfrom
copilot/write-unit-test-for-utils

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Nov 6, 2025

Adds comprehensive test coverage for the benchmark result processing script with automated CI verification. Refactors process_result.py to use testable functions instead of top-level script execution.

Changes

  • utils/process_result.py: Refactored for better testability

    • Extracted process_benchmark_result() function containing core processing logic
    • Added main() function for CLI execution
    • Maintains backward compatibility with existing CI workflows
    • Eliminates security risks from script execution patterns
  • utils/test_process_result.py: 15 unit tests covering:

    • Environment variable parsing (TP, EP_SIZE, PREFILL_GPUS, DECODE_GPUS, etc.)
    • Throughput calculations per GPU with disaggregated prefill/decode
    • Metric conversions (ms→s, tpot_ms→intvty)
    • Conditional field handling (MTP_MODE)
    • Output JSON structure validation
    • Tests import and call functions directly (no exec())
  • .github/workflows/test-utils.yml: Consolidated pytest CI workflow

    • Runs all utils tests (73 matrix-logic tests + 15 process_result tests = 88 total)
    • Triggers on any Python file changes in utils directory
    • Python 3.12, skips draft PRs
    • Replaces separate test-matrix-logic.yml and test-utils-process-result.yml workflows
  • .gitignore: Added pytest cache and Python bytecode exclusions

Test Example

def test_throughput_calculations(basic_env_vars):
    """Verifies per-GPU throughput with explicit prefill/decode GPU counts."""
    benchmark_result = {
        'max_concurrency': 10,
        'model_id': 'test/model',
        'total_token_throughput': 24000.0,
        'output_throughput': 8000.0
    }
    
    env_vars = basic_env_vars.copy()
    env_vars['TP'] = '4'
    env_vars['PREFILL_GPUS'] = '2'
    env_vars['DECODE_GPUS'] = '2'
    
    result = process_benchmark_result(benchmark_result, env_vars)
    
    # tput_per_gpu = total / tp_size = 24000/4 = 6000
    assert result['tput_per_gpu'] == 6000.0
    # output_tput_per_gpu = output / decode_gpus = 8000/2 = 4000
    assert result['output_tput_per_gpu'] == 4000.0
    # input_tput_per_gpu = (total - output) / prefill_gpus = 16000/2 = 8000
    assert result['input_tput_per_gpu'] == 8000.0

All 88 tests pass. No security alerts from CodeQL.

  • Fixes InferenceMAX/InferenceMAX#196
Original prompt

This section details on the original issue you should resolve

<issue_title>write unit test for utils/process_result.py & add pytest CI for it</issue_title>
<issue_description></issue_description>

Comments on the Issue (you are @copilot in this section)

  • Fixes InferenceMAX/InferenceMAX#196

✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

@functionstackx functionstackx marked this pull request as ready for review November 6, 2025 22:24
@functionstackx functionstackx requested a review from a team as a code owner November 6, 2025 22:24
Copilot AI review requested due to automatic review settings November 6, 2025 22:24
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds comprehensive unit testing for utils/process_result.py and sets up automated CI testing via GitHub Actions. The implementation includes 15 test cases covering core functionality such as benchmark result processing, metric conversions (milliseconds to seconds, TPOT to interactivity), GPU calculations, and various configuration scenarios. The tests use dynamic path resolution and proper fixtures for better maintainability.

Key changes:

  • Created test_process_result.py with 15 comprehensive unit tests
  • Added GitHub Actions workflow for automated pytest execution
  • Implemented dynamic path resolution for better portability

Reviewed Changes

Copilot reviewed 2 out of 3 changed files in this pull request and generated 3 comments.

File Description
utils/test_process_result.py New test file with 15 unit tests covering all major functionality of process_result.py
.github/workflows/test-utils-process-result.yml GitHub Actions workflow configuration for running pytest on relevant file changes

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.


jobs:
test:
if: github.event_name != 'pull_request' || github.event.pull_request.draft != true
Copy link

Copilot AI Nov 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] The condition skips tests on draft PRs, but the PR title contains '[WIP]' suggesting this is a work-in-progress pull request. Consider removing this condition or updating the workflow to run on draft PRs to ensure tests are executed during development.

Suggested change
if: github.event_name != 'pull_request' || github.event.pull_request.draft != true

Copilot uses AI. Check for mistakes.
Comment thread utils/test_process_result.py Outdated
try:
with patch.dict(os.environ, basic_env_vars):
# Import and execute the script
exec(open(PROCESS_RESULT_PATH).read())
Copy link

Copilot AI Nov 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using exec() with file contents is a security risk and makes the code harder to test and debug. Consider refactoring process_result.py to expose functions that can be imported and called directly, rather than executing the entire script.

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot apply changes based on this feedback

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Refactored process_result.py to expose a process_benchmark_result() function that can be imported and tested directly. Tests now call the function instead of using exec(), which is more secure and maintainable. All 15 tests still pass. Changes in commit f0353fc.

Comment thread utils/test_process_result.py Outdated
Copilot AI changed the title [WIP] Add unit test for utils/process_result.py and pytest CI Add unit tests for utils/process_result.py with pytest CI Nov 6, 2025
Copilot AI requested a review from functionstackx November 6, 2025 22:27
@functionstackx
Copy link
Copy Markdown
Collaborator

@copilot can u consolidate this pytest with .github/workflows/test-matrix-logic.yml

Copy link
Copy Markdown
Contributor Author

Copilot AI commented Nov 6, 2025

@copilot can u consolidate this pytest with .github/workflows/test-matrix-logic.yml

Done! Consolidated both workflows into .github/workflows/test-utils.yml which now runs all utils tests:

  • 73 matrix-logic tests
  • 15 process_result tests

All 88 tests passing. Changes in commit 0a7e283.

Copilot AI changed the title Add unit tests for utils/process_result.py with pytest CI Add unit tests for utils/process_result.py with consolidated pytest CI Nov 6, 2025
Copilot AI and others added 3 commits November 6, 2025 18:33
Co-authored-by: functionstackx <47992694+functionstackx@users.noreply.github.com>
…ixture

Co-authored-by: functionstackx <47992694+functionstackx@users.noreply.github.com>
Co-authored-by: functionstackx <47992694+functionstackx@users.noreply.github.com>
@functionstackx functionstackx force-pushed the copilot/write-unit-test-for-utils branch from 0a7e283 to a204048 Compare November 6, 2025 23:33
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: functionstackx <47992694+functionstackx@users.noreply.github.com>
@functionstackx functionstackx deleted the copilot/write-unit-test-for-utils branch December 4, 2025 21:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

write unit test for utils/process_result.py & add pytest CI for it

3 participants